package hot;

import java.util.ArrayList;
import java.util.List;

/**
 * @author way
 * @create 2025-03-14 21:25
 */
public class _736_partitionLabels {
    public List<Integer> partitionLabels(String s) {
        char[] cArr = s.toCharArray();
        int[] cnt = new int[26];
        List<Integer> ans = new ArrayList<>();
        for (int i = 0; i < s.length(); i++) {
            cnt[cArr[i] - 'a'] = i;
        }

        int start = 0;
        int end = 0;
        for (int i = 0; i < s.length(); i++) {
            end = Math.max(end, cnt[cArr[i] - 'a']);

            if (i == end) {
                ans.add(end - start + 1);
                start = i + 1;
            }
        }
        return ans;
    }
}
